package com.yx.interceptor;

import com.yx.utils.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;


@Slf4j
//@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String url = request.getRequestURI();

        if(url.contains("/login")){
            log.info("ok");
            return true;
        }

        String token = request.getHeader("token");

        if(token.isEmpty()){
            log.info("没有token");
            return false;
        }
        try {
            JwtUtil.parseJWT(token);
        }catch (Exception e){
            return false;
        }



        return true;
    }
}
